package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.messageBean.MessageListBean;
import com.oscar.ehome.bean.pagebean.AppListBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.util.DateUtil;
import com.oscar.ehome.view.pageview.VideoActivity;

import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/7/23
 * 应用列表
 */

public class AppListAdapter extends BaseAdapter {

    private List<AppListBean.AppList> specailList;
    private LayoutInflater mInflater;
    private Context mContext = null;

    public AppListAdapter(Context context, List<AppListBean.AppList> specailList) {
        this.mContext = context;
        this.specailList = specailList;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<AppListBean.AppList> specailList) {
        this.specailList = specailList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return specailList.size();
    }

    @Override
    public Object getItem(int position) {
        return specailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_applist, null);
            holder = new ViewHolder();
            holder.link_title = (TextView) convertView.findViewById(R.id.link_title);
            holder.link_name = (TextView) convertView.findViewById(R.id.link_name);
            holder.link_img = (ImageView) convertView.findViewById(R.id.link_img);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (specailList.size() >= 0 || specailList != null) {
            AppListBean.AppList listBean = specailList.get(position);
            String title = listBean.getRemarks();
            String name = listBean.getAppName();
            String img = C.qiniu_ip + listBean.getAppImg();

            holder.link_title.setText(title);
            holder.link_name.setText(name);
//            GildeUtils.imgLoadPic(mContext, img, holder.link_img, "net");
            GildeUtils.loadUrlImages(img, holder.link_img, mContext);

        }

        return convertView;
    }

    class ViewHolder {
        TextView link_title;
        ImageView link_img;
        TextView link_name;

    }
}
